﻿using System;

namespace Mindless
{
    /// <summary>
    /// A location on a board. These are immutable.
    /// </summary>
    struct Location : IEquatable<Location>
    {
        /// <summary>
        /// Constructs a new location.
        /// </summary>
        public Location(int x, int y)
        {
            this.x = x;
            this.y = y;
        }

        /// <summary>
        /// X-coord of the location.
        /// </summary>
        public int X
        {
            get { return this.x; }
        }
        int x;

        /// <summary>
        /// Y-coord of the location.
        /// </summary>
        public int Y
        {
            get { return this.y; }
        }
        int y;

        public static Location Null = new Location(-1, -1);

        public bool Equals(Location loc)
        {
            return (this.x == loc.x) && (this.y == loc.y);
        }

        public override bool Equals(object obj)
        {
            return this.Equals((Location) obj);
        }

        public static bool operator ==(Location a, Location b)
        {
            return a.Equals(b);
        }

        public static bool operator !=(Location a, Location b)
        {
            return !a.Equals(b);
        }

        public override int GetHashCode()
        {
            return this.x + this.y;
        }

        /// <summary>
        /// Adds a vector to a location, producing a new location.
        /// </summary>
        public static Location operator +(Location loc, Vector vec)
        {
            return new Location(loc.x + vec.X, loc.y + vec.Y);
        }

        /// <summary>
        /// Display string.
        /// </summary>
        public override string ToString()
        {
            return string.Format("({0},{1})", this.x, this.y);
        }
    }
}